/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.senac.maisconhecimento.dao;

import java.sql.Connection;
import org.hibernate.Session;

/**
 *
 * @author Marcus Lemos
 */
public class GenericDao<T> {

    Connection conexao = null;
    private Session session = HibernateUtil.getSessionFactory().openSession();

    public Session getSession() {
        return HibernateUtil.getSession();
    }  

    public void inserir(T p) {
        try {
            session.beginTransaction();
            session.save(p);
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
        }
    }

    public void delete(T p) {
        try {
            session.beginTransaction();
            session.delete(p);
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
        }
    }

    public void alterar(T p) {
        try {
            session.beginTransaction();
            session.merge(p);
            session.getTransaction().commit();
        } catch (Exception e) {
            session.getTransaction().rollback();
        }
    }
}
